	var url = "/getAlbumJSON";

	var gotAlbums = function (meta){
		var newDiv = DIV();
		for (alb in meta){
			appendChildNodes(newDiv, DIV({"id":"album"},repr(meta[alb].name)));
		}		
		swapDOM("artist" + meta[0].artist, newDiv);
	}

	var albumsFailed = function (err){
		
	}
	

function requestAlbums(artist){
		log("making json object");
		a = loadJSONDoc("/get_albums_JSON", {id: artist});
		log("adding callbacks to json object");
		a.addCallbacks(gotAlbums, albumsFailed);
	}


var gotArtists = function(meta){
		var artistDiv = getElement("artist"+meta[0].artist);
		var newDiv = DIV();
		for (alb in meta){
			appendChildNodes(newDiv, 
				DIV({"id":"artist"}, 
					A({'href':'#', 'onclick': 'requestAlbums(' + repr(meta[alb].id) + ')'}, repr(meta[alb].name)),
					DIV({"id":"artist" + repr(meta[alb].id)})
					)
			);
		}		
		swapDOM("artist_ph", newDiv);

}
var artistsFailed = function(err){

}

function requestArtists(){
		log("making json object");
		a = loadJSONDoc("/get_artists_JSON");
		log("adding callbacks to json object");
		a.addCallbacks(gotArtists, artistsFailed);

}
addLoadEvent(requestArtists);
